package com.example.himalayaproject.find.broadcast.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.himalayaproject.R;
import com.example.himalayaproject.find.broadcast.bean.LocalRadios;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/3.
 */

public class BroadcastAdapter extends RecyclerView.Adapter<BroadcastAdapter.ViewHolder> {
    private Context context;
    private List<LocalRadios> datas;

    public BroadcastAdapter(Context context) {
        this.context = context;
        datas = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder holder = new ViewHolder(LayoutInflater.from(context).inflate(R.layout.broadcast_item, parent, false));

        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        LocalRadios localRadios = datas.get(position);
        holder.nameTextView.setText(localRadios.getName());
        if (localRadios.getProgramName() == null){
            holder.currTextView.setText("暂无节目单");
        } else {
            holder.currTextView.setText("正在直播："+localRadios.getProgramName());
        }
        float count = ((float) Integer.parseInt(localRadios.getPlayCount()))/10000;
        holder.numberTextView.setText(count+"万人");
        Picasso.with(context).load(localRadios.getCoverSmall()).into(holder.srcImage);
    }



    public void addAll (Collection<? extends LocalRadios> collection) {
        int size = datas.size();
        datas.addAll(collection);
        notifyItemRangeInserted(size,collection.size());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
            private TextView nameTextView,currTextView,numberTextView;
            private ImageView imageView,srcImage;
            public ViewHolder(View itemView) {
                super(itemView);
                nameTextView = ((TextView) itemView.findViewById(R.id.bct_item_name));
                currTextView = ((TextView) itemView.findViewById(R.id.bct_item_current));
                numberTextView = ((TextView) itemView.findViewById(R.id.bct_item_number));
                imageView = ((ImageView) itemView.findViewById(R.id.bct_item_play));
                srcImage = ((ImageView) itemView.findViewById(R.id.bct_item_src));

            }
        }


}
